#!/bin/sh
#
# Sentinel Crontab v2.1
# $Id: sentinelchk,v 1.1 2003/12/31 02:08:08 jeremy Exp $
#
# This is a script suitable for use in a crontab.  It checks to make sure
# your ircd is running.  YOU NEED A SEPARATE CRON JOB FOR EACH IRCD.  If your
# ircd isn't found, it'll try to start it back up.
#
# You'll need to edit this script for your Sentinel.
#
# To check for your ircd every 10 minutes, put the following line in your
# crontab:
#    0,10,20,30,40,50 * * * *   /home/mydir/sentinelchk
# And if you don't want to get email from crontab when it checks you ircd,
# put the following in your crontab:
#    0,10,20,30,40,50 * * * *   /home/mydir/sentinelchk >/dev/null 2>&1
#
# change this to the mail address to mail output to:
#MAIL=me
# change this to the directory you run your Sentinel from:
dir="/home/ircd/services/Sentinel"

# change this to the name of your Sentinel's file in that directory:
sentinelexe="bin/sentinel"

# I wouldn't touch this if I were you.
sentinelname="etc/sentinel.pid"

# lets get the date
# Change this for the output date/time
date=`date "+(%d/%m/%Y %H:%M:%S)"`

########## you probably don't need to change anything below here ##########

cd $dir
if test -r $sentinelname; then
  # there is a pid file -- is it current?
  sentinelpid=`cat $sentinelname`
  if `kill -CHLD $sentinelpid >/dev/null 2>&1`; then
    # it's still going
    # back out quietly
    echo "$date Sentinel runnng. Exiting..."
    exit 0
  fi
  echo "$date Stale $sentinelname file (erasing it)"
  rm -f $sentinelname
fi
echo "$date Couldn't find the Sentinel running.  Reloading it..."
./$sentinelexe
